﻿package  
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author Tuan
	 */
	public class mcNewsElement extends MovieClip
	{
		//khai bao bien thanh vien o day
		var loader:Loader; //anh luu vao day
		var xml:XML;
		
		public function mcNewsElement(myXml:XML) 
		{
			if ( null != myXml)
			{
				xml = myXml as XML;
				txtTitle.text = xml.title;
				txtBegin.text = xml.begin;
				txtID.text = xml.@id;
				loader = new Loader();
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoadedComplete);
				if (xml.img.@src != "")
				{
					var request:URLRequest = new URLRequest(xml.img[0].@src);
				}
				//trace(xml.img[0].@src);
				loader.load(request);
			}
		}
		
		public function onImageLoadedComplete(e:Event):void
		{
			locateImage(loader, img);
		}
		
		//dat anh vao dung vi tri
		private function locateImage(child:Loader, parent:MovieClip)
		{
			var a:Number = child.width / child.height;
			if (a > 1.4)
			{
				child.width = parent.width - 10;
				child.height = child.width / a;
			}
			else
			{
				child.height = parent.height - 10;
				child.width = child.height * a;
			}
			parent.addChild(child);
		}
	}
}